<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateLessonStudentTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
        Schema::create('lesson_students', function(Blueprint $table){
            $table->increments('id')->comment('主键id');

            $table->unsignedInteger('lesson_id')->comment('对应课程的id');
            $table->foreign('lesson_id')->references('id')->on('lessons')->onDelete('cascade');

            $table->unsignedInteger('student_id')->comment('对应学生的id');
            $table->foreign('student_id')->references('id')->on('users')->onDelete('cascade');

            $table->unsignedInteger('status_id')->default(2)->comment('学生的状态');
            $table->foreign('status_id')->references('id')->on('lesson_student_status')->onDelete('cascade');

            /*
             * 测试时所使用的SQLite，其timestamp字段不会自动更新
             */
            if( ! App::environment('testing') ){
                $table->timestamps();
            }

        });
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('lesson_students');
	}

}
